package view;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Rectangle;

import javax.swing.*;
import javax.swing.border.TitledBorder;

import model.TaarifModel;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;


/**
 * This is the Complaint Details GUI  extends AbstractGUI
 * @author Tal Panika	
 */ 
public class ComplaintDetailsGUI  extends AbstractGUI
{
	private JLabel compensationLabel = null;
	private JLabel uidLabel = null;
	private JLabel fNameLabel = null;
	private JLabel lNameLabel = null;
	private JLabel statusLabel = null;
	private JTextArea complaintArea = null;
	private JLabel ReplyLabel = null;
	private JTextArea ReplyTextArea = null;
	private JCheckBox CompCheckBox=null;
	private JButton replyButton = null;	
	private JPanel contentPane=null;
	private JLabel wrnMessage=null;
	ArrayList<String> sub=null;
	private JComboBox sCombo=null;
	private JComboBox Combo=null;

	/**
	 * This is ComplaintDetailsGUI constructor.
	 * 
	 */
	public ComplaintDetailsGUI ()
	{ 		  
		
		super();
		
		 //Complain tDetails panel
		   contentPane=new JPanel();	
		  //Main Panel 
		   contentPane.setBorder(new TitledBorder(null, "Feedback Details", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		   contentPane.setLayout(null);
		   contentPane.setOpaque(true);
		  // contentPane.add(getCombo() );
		   contentPane.add( getUIDLabel());
		   contentPane.add(getfNameLabel());
		   contentPane.add(getlNameLabel());
		   contentPane.add(getStatusLabel());
		   contentPane.add(getComplaintArea());
			contentPane.add(getReplyLabel());
			contentPane.add(getReplyArea());
			 contentPane.add(getCompCheckBox());
			contentPane.add(geReplyButton());
			contentPane.add(getBackButton(),BorderLayout.SOUTH);
			contentPane.add(getWrnMessage());
	        

			  //Frame
		        this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		        this.setTitle("Feedback Details Window");
		        this.setContentPane(contentPane);  
		        
		       
		       
		      
			    this.setLocationRelativeTo(null); //This will center the JFrame in the middle of the screen
		        this.setLocationByPlatform(true);
		        this.setSize(500, 500);         
	               
	  }
		
	/**
	 * This method initializes UID  Label
	 */
	private JLabel getUIDLabel() {
		if (uidLabel == null) {
			  uidLabel = new JLabel(" ");
			   uidLabel.setBounds(new Rectangle(56, 50, 64, 17));
			
		}
		return uidLabel;
	}
	
	/**
	 * This method initializes fName Label
	 */
	private JLabel getfNameLabel() {
		if (fNameLabel == null) {
			fNameLabel = new JLabel(" ");
			   fNameLabel.setBounds(new Rectangle(99, 50, 100, 17));
			  
		}
		return fNameLabel;
	}
	
	/**
	 * This method initializes lName Label
	 */
	private JLabel getlNameLabel() {
		if (lNameLabel == null) {
			lNameLabel = new JLabel(" ");
			lNameLabel.setBounds(new Rectangle(187, 50, 119, 17));
			 
		}
		return lNameLabel;
	}
	
	/**
	 * This method initializes Status Label
	 */
	private JLabel getStatusLabel() {
		if (statusLabel == null) {
			statusLabel = new JLabel();
			statusLabel.setBounds(new Rectangle(328, 50, 119, 17));
			  
		}
		return statusLabel;
	}
	
	/**
	 * This method initializes Reply Label
	 */
	private JLabel getReplyLabel() {
		if (ReplyLabel == null) {
			ReplyLabel = new JLabel();
			ReplyLabel.setBounds(new Rectangle(50, 169, 100, 17));
			   SetGenLabel("Reply:",ReplyLabel);
		}
		return ReplyLabel;
	}
	
	/**
	 * This method initializes Compensation CheckBox
	 */
	private JCheckBox getCompCheckBox() {
		if (CompCheckBox == null) {
			  CompCheckBox = new JCheckBox("Compensation Package:");
		        CompCheckBox.setBounds(50, 331, 165, 23);
		        CompCheckBox.addActionListener(new ActionListener(){
		        
		        	public void actionPerformed(ActionEvent e) {
		        		if (CompCheckBox.isSelected())
		        			Combo.setVisible(true);
		        		else  
		        			Combo.setVisible(false);
		        	}
		        }
		        
		        );
		}//end if
		
		return CompCheckBox;
	}

	/**
	 * This method initializes  ComboBox
	 */
	private JComboBox getCombo() {	
		if (sCombo == null) {	
			sCombo = new JComboBox();
			sCombo.setBounds(new Rectangle(230, 323, 180, 35));		
			
		}
		return sCombo;
	}
	
	
	/**
	 * This method initializes Compliant Details Area
	 */
	private JTextArea getComplaintArea() {
		if (complaintArea == null) {
			complaintArea = new JTextArea();
			complaintArea.setBounds(new Rectangle(50, 70, 350, 100));
			complaintArea.setBorder(BorderFactory.createLineBorder(Color.BLACK));
			
		}
		return complaintArea;
	}
	
	/**
	 * This method initializes Reply Area	
	 */
	private JTextArea getReplyArea() {
		if (ReplyTextArea == null) {
			ReplyTextArea = new JTextArea();			
			ReplyTextArea.setBounds(new Rectangle(50, 200, 350, 100));
			ReplyTextArea.setBorder(BorderFactory.createLineBorder(Color.BLACK));
			
		}
		return ReplyTextArea;
	}
	
	/**
	 * This method initializes Send Reply Button	
	 */
	private JButton geReplyButton() {
		if (replyButton == null) {
			replyButton = new JButton();
			replyButton.setBounds(new Rectangle(67, 398, 100, 35));
			replyButton.setText("Send Reply");
			
		}
		return replyButton;
	}
	

	/**
	 * This method creates warning message if currently is null.
	 * @return JLabel type.
	 */
	private JLabel getWrnMessage() {
		if (wrnMessage == null) {
			wrnMessage = new JLabel();
			wrnMessage.setForeground(Color.RED);
			wrnMessage.setBounds(70, 16, 320, 23);
			wrnMessage.setVisible(false);
		}
		return wrnMessage;
	}
	
	/**
	 * This method initializes Back Button	
	 */
	private JButton getBackButton() {
		if (backButton == null) {
			backButton = new JButton();
			backButton.setBounds(new Rectangle(263, 398, 100, 35));
			backButton.setText("Back");
		
		}
		return backButton;
	}
	
	
	

	/**
	 * *********************************Public Methods 
	 */
	/**
	 * This method set ArrayList of sub-description.
	 * @param ArrayList<String> s
	 */
	public void setArrayDescr(ArrayList<TaarifModel> t)
	{
		this.sub=new ArrayList<String>();
		 for(int i=0;i<t.size();i++)
			 sub.add(t.get(i).getdescription());
	}
	
	
	/**
	 * This method return selected item from combobox .
	 * @param comboBox
	 */
	public int getItemSelectedIndex()
	{
		    int index;
				index=Combo.getSelectedIndex();
				
				System.out.println("selected:"+index);
			return	index;
			
	}
		
	/**
	 * This method set data to combo from data retrieve from db and 
	 * void
	 */
	
	public void setCombo()
	{	 
		Combo=this.getCombo();
		Combo.removeAllItems();
		
		Combo.setVisible(false);
		
		Combo.addItem("Compenstation Type->");
	    
	    
		for(int i=0; i<sub.size();i++)
			Combo.addItem(sub.get(i));
			
		contentPane.repaint();
		contentPane.validate();

	contentPane.add(Combo);
		
	}
	/**
	 * This method dispose Combo
	 * @param void
	 */
	
	public void disposeCombo()
	{
		if(Combo!=null)
		{
			Combo.setVisible(false);
			Combo.removeAllItems();
			Combo = null;
			
		}
			
	}
	
	
	/**
	 * This method display Warning Message.
	 * @param void	 
	 * */
	
	public void displayWrnMessage(String msg){
		wrnMessage.setText(msg);
		wrnMessage.setVisible(true);
	}
	
	/**
	 * This method return UID  Label
	 */
	public JLabel getUID() {
		
		return uidLabel;
	}
	
	/**
	 * This method return fName Label
	 */
	public JLabel getfName() {
	
		return fNameLabel;
	}
	
	/**
	 * This method return lName Label
	 */
	public JLabel getlName() {
		
		return lNameLabel;
	}
	
	/**
	 * This method initializes Status Label
	 */
	public JLabel getStatus() {
	
		return statusLabel;
	}
	
	/**
	 * This method set JLablel Text genric
	 */
	public void SetGenLabel(String text,JLabel label) {
		if (label != null) {

			label.setText(text);
		}
	}
	
	/**
	 * This set complaintField Area.
	 * @param String Msg 
	 * */
	
	public void setComplaintDetArea(String msg){
		complaintArea.setText(msg);
		complaintArea.setVisible(true);
	}
	
	/**
	 * This method return Reply Area
	 */
	public String getReply() {
		return ReplyTextArea.getText();
	}
	
	
	/**
	 * This method add action listener to Reply button.
	 * @param listener
	 */
	public void addReplyActionListener(ActionListener listener){
		replyButton.addActionListener(listener);
	}
	
	
	/**
	 * This method return if check Box is Pressed
	 * true-is selected,false not
	 */
	
	public boolean checkBoxPressed()
	{
		if (CompCheckBox.isSelected())
			return true;
		   
		return false;
	}
	
	
	/**
	 * This method return -simulate back button pressed .
	 * @param listener
	 */
	public void clickBackButton()
	{
		this.getBackButton().doClick();
	}
	
}
